$(document).ready(function(){
    
    let $username = $('#username');
    let $password = $('#password');

    $('#submit').click(function (){
        let userinfo = {
            username: $username.val(),
            password: $password.val(),
        };
        console.log(userinfo);

        $.ajax({
            type: 'POST',
            url: 'http://dorm.zhangqx.com:8002/api/login',
            // url: 'http://101.133.131.59:8002/api/login',
            data: userinfo,
            success: function(response) {
                console.log(response);
                if(response.status == 1) {
                    let token = response.access_token;
                    localStorage.getItem("token");
                    localStorage.setItem("token", token);

                    let name = response.name;
                    let studentid = response.studentid;
                    let gender = response.gender;
                    localStorage.setItem("name", name);
                    localStorage.setItem("studentid", studentid);
                    localStorage.setItem("gender", gender);

                    setTimeout("window.location.href = './../homepage/homepage.html'", 3000);
                }
                alert(response.message)


            },
            error: function() {
                alert('error login');
            }
        });
    });
});